
import React, { Component } from 'react';
import Son from './Son';
import {withRouter} from "../HOC/hoc"

class LifeCycle extends Component {

  constructor(props){
    super(props);
    console.log("constructor");
    this.state ={
      count:3
    }
  }

  componentWillMount(){
    console.log("componentWillMount");
  }

  componentDidMount(){
    console.log("componentDidMount");
  }

  // 组件应该更新吗？
  shouldComponentUpdate(){
    console.log("this.state.count",this.state.count);
    console.log("shouldComponentUpdate");
    return false;
  }

  // 状态发生变化时，会调用的钩子函数。
  componentWillUpdate(){
    console.log("componentWillUpdate");
  }

  // 属性发生变化时，模板渲染前。
  componentWillReceiveProps(){
    console.log("componentWillReceiveProps");
  }

  componentDidUpdate(){
    console.log("componentDidUpdate");
  }


  changeCount=()=>{
    this.props.history();
    this.setState({
      count:this.state.count+1
    })
  }

  render() {
    console.log("render ");
    return (
      <div>
        <h1>生命周期</h1>
        <p>countL:{this.state.count}</p>
        <input type="button" value="修改count" onClick={this.changeCount} />
        <hr/>
        <Son age="12"></Son>
      </div>
    )
  }
}


export default withRouter(LifeCycle);